package com.mce.nebula.controller;

import com.mce.nebula.dto.ApiResponse;
import com.mce.nebula.service.UserSourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 用户源控制器
 * 对应Python的UserSourceView - 飞书API集成接口
 */
@Slf4j
@RestController
@RequestMapping("/api/user-source")
@Tag(name = "用户源管理", description = "飞书API集成相关接口")
@RequiredArgsConstructor
public class UserSourceController {
    
    private final UserSourceService userSourceService;
    
    @GetMapping("/feishu")
    @Operation(summary = "发送飞书消息", description = "使用飞书API发送消息")
    public ResponseEntity<ApiResponse<Map<String, Object>>> sendFeishuMessage(
            @RequestParam(required = false) String smsType,
            @RequestParam(required = false, defaultValue = "open_id") String receiveIdType,
            @RequestParam(required = false, defaultValue = "你好") String content) {
        try {
            Map<String, Object> result = userSourceService.sendFeishuMessage(smsType, receiveIdType, content);
            return ResponseEntity.ok(ApiResponse.success(result, "消息发送成功"));
        } catch (Exception e) {
            log.error("Failed to send feishu message", e);
            return ResponseEntity.badRequest()
                .body(ApiResponse.error(400, e.getMessage()));
        }
    }
}
